package com.quanyue.music.file.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.quanyue.music.domain.constant.UserRole;
import com.quanyue.music.domain.entity.FmSort;
import com.quanyue.music.file.service.FMSortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "FM分类")
@Scope(role = UserRole.MANAGER)
@RestController
@RequestMapping("/api")
public class FMSortController {
    @Autowired
    private FMSortService fmSortService;

    @ApiOperation(value = "添加分类")
    @PostMapping(value = "/fm/sort/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> add(@RequestBody FmSort sort) {
        fmSortService.add(sort);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "更新分类信息")
    @PostMapping(value = "/fm/sort/update", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> update(@RequestBody FmSort sort) {
        fmSortService.update(sort);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping(value = "/fm/sort/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> delete(@RequestParam("id") String id) {
        fmSortService.delete(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "获取分类列表")
    @GetMapping(value = "/fm/sort/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<FmSort>> findList() {
        return ServiceResult.success(fmSortService.findList());
    }
}
